package com.onlinelibrary.controller;

import com.onlinelibrary.pojo.User;
import com.onlinelibrary.result.Result;
import com.onlinelibrary.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RequiredArgsConstructor
@RestController
@RequestMapping("/user")
public class UserController {


    private final UserService userService;

    @GetMapping("/list")
    Result list() {
        return userService.list();
    }

    @PostMapping("/getUser")
    Result getUser(@RequestBody User user) {
        return userService.getUser(user);
    }

    @PostMapping("/register")
    Result register(@RequestBody User user) {
        return userService.register(user);
    }

    @PostMapping("/login")
    Result login(@RequestBody User user) {
        return userService.login(user);
    }

    @PostMapping("/sendEmailCode")
    Result sendEmailCode(@RequestBody User user) {
        return userService.sendEmailCode(user);
    }

    @PostMapping("/loginByEmail")
    Result loginByEmail(@RequestBody User user) {
        return userService.loginByEmail(user);
    }

    @PostMapping("/updateUser")
    Result updateUser(@RequestBody User user) {
        System.out.println(user);
        return userService.updateUser(user);
    }

    @PostMapping("/updateHeadUrl")
    Result updateHeadUrl(@RequestParam("file") MultipartFile file, @RequestParam("id") String id) {
        return userService.updateHeadUrl(file, id);
    }

    //getTableData
    @PostMapping("/getTableData")
    Result getTableData(@RequestBody User user) {
        return userService.getTableData(user);
    }

    @PostMapping("/deleteUser")
    Result deleteUser(@RequestBody User user) {
        return userService.deleteUser(user);
    }


    @PostMapping("/insertBookHouse")
    Result insertBookHouse(@RequestBody User user) {
        return userService.insertBookHouse(user);
    }

    @PostMapping("/getBookHouse")
    Result getBookHouse(@RequestBody User user) {
        return userService.getBookHouse(user);
    }

    @PostMapping("/findByIsbns")
    Result findByIsbns(@RequestBody User user) {
        return userService.findByIsbns(user.getName());
    }

   // /deleteByIsbn
    @PostMapping("/deleteByIsbn")
    Result deleteByIsbn(@RequestBody User user) {
        return userService.deleteByIsbn(user);
    }


    @PostMapping("/updatePassword")
    Result updatePassword(@RequestBody User user) {
        return userService.updatePassword(user);
    }

    @PostMapping("/updateUserBack")
    Result updateUserBack(@RequestBody User user) {
        return userService.updateUserBack(user);
    }
}